package problem.ejercicio2;

import java.util.Vector;
import java.util.StringTokenizer;
import org.junit.Test;
import static org.junit.Assert.assertEquals;


public class RedTest {

	 @Test
	   public void simpleRedTest() {
	      Red rd = new Red();
	      Vector<Amistad> amistades = parseAmistades( "" );
	      assertEquals(0,rd.run( "esteban", "irene", amistades));
	      amistades = parseAmistades( "irene alejandro;alejandro paula;alejandro esteban" );
	      assertEquals(2,rd.run( "esteban", "irene", amistades));
	      amistades = parseAmistades( "irene alejandro;alejandro paula;marina esteban" );
	      assertEquals(0,rd.run( "esteban", "irene", amistades));
	      amistades = parseAmistades( "marina alejandro;alejandro paula;marina esteban" );
	      assertEquals(0,rd.run( "esteban", "irene", amistades));
	      amistades = parseAmistades( "irene alejandro;irene paula;irene emilio;irene esteban" );
	      assertEquals(1,rd.run( "esteban", "irene", amistades));
	      amistades = parseAmistades( "irene alejandro;alejandro paula;irene paula;paula emilio;esteban emilio;emilio marina;marina esteban" );
	      assertEquals(3,rd.run( "esteban", "irene", amistades));
	      amistades = parseAmistades( "irene alejandro;alejandro paula;irene paula;paula emilio;esteban emilio;emilio marina;marina esteban;alejandro marina;" );
	      assertEquals(3,rd.run( "esteban", "irene", amistades));
	 }
	     
	     public static Vector<Amistad> parseAmistades( String line ) {
	         Vector<Amistad> lst = new Vector<Amistad>();	        
	         
	         StringTokenizer st = new StringTokenizer( line, ";" );
	         while ( st.hasMoreTokens() ) {
	            lst.add( parseAmistad( st.nextToken() ) );
	         }

	         return lst;
	      }

	      private static Amistad parseAmistad( String string ) {
	         StringTokenizer st = new StringTokenizer( string, " " );
	         return new Amistad( st.nextToken() , st.nextToken());
	      } 
	     
}
